class_name Arrow
extends RigidBody2D

var face_direction: float

@onready var asc: AbilitySystemComponent = %AbilitySystemComponent

@onready var animator: AnimatedSprite2D = %Animator


func _ready() -> void:
	body_entered.connect(_on_body_entered)

	animator.play("default")

	get_tree().create_timer(1.0).timeout.connect(queue_free)

	if face_direction == -1.0:
		animator.flip_h = true
	
	linear_velocity.x = face_direction * asc.attribute_set.get_attribute("speed").current_value


func _on_body_entered(body: Node) -> void:
	asc.ability_manager.try_apply_ability_by_name("arrow_attack", body.asc)
